Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add way to express that no values are expected with check-cfg #119930

Merged
merged 1 commit into from
Jan 17, 2024

Conversation

Urgau
Copy link
Member

@Urgau Urgau commented Jan 13, 2024

This PR adds way to express no-values (no values expected) with --check-cfg by making empty values() no longer mean values(none()) (internal: &[None]) and now be an empty list (internal: &[]).

Context

Currently --check-cfg has a way to express that any value is expected with values(any()), but has no way to do the inverse and say that no value is expected.

This would be particularly useful for build systems that control a config name and it's values as they could always declare a config name as expected and if in the current state they have values pass them and if not pass an empty list.

To give a more concrete example, Cargo --check-cfg currently needs to generate:

  • --check-cfg=cfg(feature, values(...)) for the case with declared features
  • and --check-cfg=cfg() for the case without any features declared

This means that when there are no features declared, users will get an unexpected config name but from the point of view of Cargo the config name feature is expected, it's just that for now there aren't any values for it.

See Cargo check_cfg_args function for more details.

De-specializing empty values()

To solve this issue I propose that we "de-specialize" empty values() to no longer mean values(none()) but to actually mean empty set/list. This is one of the last source of confusion for my-self and others with the --check-cfg syntax.

The confusing part here is that an empty values() currently means the same as values(none()), i.e. an expected list of values with the none variant (as in #[cfg(name)] where the value is none) instead of meaning an empty set.

Before the new cfg() syntax, defining the none variant was only possible under certain circumstances, so in #111068 I decided to make values() to mean the none variant, but it is no longer necessary since #119473 which introduced the none() syntax.

A simplified representation of the proposed "de-specialization" would be:

Syntax List/set of expected values
cfg(name)/cfg(name, values(none())) &[None]
cfg(name, values()) &[]

Note that I have my-self made the mistake of using an empty values() as meaning empty set, see rust-lang/cargo#13011.

@rustbot label +F-check-cfg
r? @petrochenkov
cc @epage

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. F-check-cfg --check-cfg labels Jan 13, 2024
@rust-log-analyzer

This comment has been minimized.

@Urgau Urgau force-pushed the check-cfg-empty-values-means-empty branch from 35f649e to 41b69aa Compare January 13, 2024 16:26
@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Jan 17, 2024

📌 Commit 41b69aa has been approved by petrochenkov

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 17, 2024
@bors
Copy link
Contributor

bors commented Jan 17, 2024

⌛ Testing commit 41b69aa with merge c58a5da...

@bors
Copy link
Contributor

bors commented Jan 17, 2024

☀️ Test successful - checks-actions
Approved by: petrochenkov
Pushing c58a5da to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jan 17, 2024
@bors bors merged commit c58a5da into rust-lang:master Jan 17, 2024
12 checks passed
@rustbot rustbot added this to the 1.77.0 milestone Jan 17, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (c58a5da): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
1.2% [0.7%, 1.6%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.3% [-4.1%, -1.4%] 3
All ❌✅ (primary) - - 0

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
5.7% [3.1%, 9.3%] 17
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 665.924s -> 664.091s (-0.28%)
Artifact size: 308.39 MiB -> 308.23 MiB (-0.05%)

bors added a commit to rust-lang/cargo that referenced this pull request Jan 18, 2024
Go back to passing an empty `values()` when no features are declared

This PR is basically a revert of #13011, which made the `--check-cfg` invocation be `cfg()` when no features are declared instead of `cfg(feature, values())` since it meant declaring that the config `feature` were to be available in this form: `#[cfg(feature)]`, which is not the case.

Thankfully after some brainstorming, I [proposed](rust-lang/rust#119930) changing the behavior of empty `values()` in `rustc` to no longer imply the _none_ value and simply create an empty set of expected values. 😃

For Cargo, always using `cfg(feature, values(...))` means that the config `feature` is always expected, regardless of the number of features. This makes the warning better, as it will now always be `unexpected config value` (instead of `unexpected config name`). 🎉

Fixes #13011 (comment) as well as the concern in the [tracking issue](#10554).

r? `@epage`
stupendoussuperpowers pushed a commit to stupendoussuperpowers/cargo that referenced this pull request Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-check-cfg --check-cfg merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants